var _conditions = {};
var _orderStyle = '';
$(function () {
    $.fn.raty.defaults.path = '/by-webhtml/assets/image';
    $('#by_index_search_btn').on('click', byIndexSearchPage);

    $('html, body').on('click', '#com_list_content .page a', function(e) {
        e.stopPropagation();
        _conditions = {"page": judgePage($(this).text())};
        byIndexSearchData(_conditions);
    }).on('click', '#com_list_ul li a, #commend ul.teamDiv li a', function (e) {
        e.stopPropagation();
        $('html, body').animate({scrollTop: 0});
        var userId = $(this).nextAll('input').val();
        loadDetailPage(userId);
    }).on('click', '#com_list_ul li img', function (e) {
        e.stopPropagation();
        var userId = $(this).nextAll('input').val();
        loadDetailPage(userId);
    }).on('click', '#reviews .page a', function(e) {
        e.stopPropagation();
        var _cpage = judgePage($(this).text());
        searchComments(_cpage);
    });

    $('html, body').on('click', '.nav li:gt(0)', function (e) {
        $("#keyId").val("");
        listDivHidden();
        e.stopPropagation();
        // var this_li_index = $('.nav li').index($(this));
        var $this_li_txt = $(this).text();
        $('.nav li').removeClass('active');
        $(this).addClass('active');
        var city = $("#mainCity span").html();
        if(city == '全国'){
            city = null;
        }
        var channelId = $(this).attr('channel_id');
        if (channelId && $this_li_txt != '婚礼案例') {
            _conditions = {"page": 1, "channel_id": channelId, "city": city};
            byIndexSearchPage();
        } else if ($this_li_txt == '婚礼案例') {
            _caseConditions = {"page": 1, "city": city};
            byIndexCasePage();
        }
    });

    // 婚期筛选条件
    $('html, body').on('click', '#com_list_content ul li:eq(0) a', function (e) {
        e.stopPropagation();
        var _val = $(this).text();
        _conditions.conv_date = '';
        byIndexSearchData(_conditions);
    });
    // 價格篩選條件
    $('html, body').on('click', '#com_list_content ul li:eq(1) a', function (e) {
        e.stopPropagation();
        var _val = $(this).text();
        _conditions.price = _val;
        $('#com_list_content ul li:eq(1) em a').removeClass('cur');
        $(this).addClass('cur');
        byIndexSearchData(_conditions);
    });
    // 區域篩選條件
    $('html, body').on('click', '#com_list_content ul li:eq(2) a', function (e) {
        e.stopPropagation();
        var _val = $(this).text();
        _conditions.area = _val == '不限' ? '0' : _val;
        $('#com_list_content ul li:eq(2) em a').removeClass('cur');
        $(this).addClass('cur');
        byIndexSearchData(_conditions);
    });
    // 商品选择
    $('html, body').on('click', '#mer_detail_production span', function (e) {
        e.stopPropagation();
        var _clz = $(this).attr('class');
        if (_clz && _clz.indexOf('cur') != -1) {
            $(this).removeClass('cur');
        } else {
            $('#mer_detail_production span').removeClass('cur');
            $(this).addClass('cur');
        }
    });
    // 午餐/晚餐选择
    $('html, body').on('click', '.detaEm1', function (e) {
        e.stopPropagation();
        $('.detaEm1').removeClass('cur');
        $(this).addClass('cur');
    });
    // 筛选各个按钮点击事件
    $('html, body').on('click', '#com_list_content ul li:eq(3) label a', function (e) {
        e.stopPropagation();
        var _clz = $(this).attr('class');
        var $vle = $(this).text();
        var _orderType = '';
        if (_clz && _clz.indexOf('cur') != -1) {
            if ($vle != '综合') {
                var isAsc = $(this).hasClass('order_asc');
                if (isAsc) {
                    $(this).removeClass('order_asc').addClass('order_desc');
                    _orderType = 'desc ';
                } else {
                    $(this).removeClass('order_desc').addClass('order_asc');
                    _orderType = '';
                }
            } else {
                return;
            }
        } else {
            $('#com_list_content ul li:eq(3) label a').removeClass('cur order_asc order_desc');
            $(this).addClass('cur');
            if ($vle == '综合') {
                _orderStyle = '';
            } else if ($vle == '价格') {
                _orderStyle = ' biz_price ';
                $(this).addClass('order_asc');
            } else if ($vle == '浏览量') {
                _orderType = 'desc ';
                _orderStyle = ' biz_view_count ';
                $(this).addClass('order_desc');
            } else if ($vle == '好评率') {
                _orderType = 'desc ';
                _orderStyle = ' biz_star ';
                $(this).addClass('order_desc');
            }
        }
        _conditions.orderBy = _orderStyle + _orderType;
        byIndexSearchData(_conditions);
    }).on('click', '#md_add_trolley', function (e) { // 加入购物车按钮点击事件
        e.stopPropagation();
        $(".cartDiv em").fadeIn();
        var _proId = $('#mer_detail_production span.cur input').val();
        var _schDate = $('#md_mer_date').val();
        var _dinType = $('#md_mer_date').nextAll('.cur').text();
        var _qtyItem = $('#md_mer_qty_item').val();
        if (!_proId) {
            alert('请选择商家产品！');
            return;
        } else if (!_schDate) {
            alert('请选择预约时间！');
            return;
        } else if (!_dinType) {
            alert('请选择“午餐”或是“晚宴”！');
            return;
        } else if (!_qtyItem) {
            alert('请选择数量！');
            return;
        }
        $.ajax({
            type: 'get',
            url: '/htmlWeb/isHaveOrder.json',
            data: {
                "userId": $('#md_mer_detail_id').val(),
                "scheduleDate": $('#md_mer_date').val(),
                "scheduleType": (_dinType == '午餐' ? 1 : 2)
            },
            dataType: 'json',
            success: function (rnData) {
                if (rnData && rnData.result == '1') {
                    addProduct(e);
                    $.ajax({
                        type: 'get',
                        url: '/loginWeb/isLogin.json',
                        dataType: 'json',
                        data: {},
                        success: function (ret) {
                            if (ret.isLogin == 'OK') {
                                var _1 = $('#md_mer_date').nextAll('.cur').text();
                                var _data = {
                                    "biz_user_id": $('#md_mer_detail_id').val(),  // 商家ID
                                    "product_id": $('#mer_detail_production span.cur input').val(),
                                    "schedule_date": $('#md_mer_date').val(),
                                    "dinner_type": _1 == '午餐' ? '午宴' : _1,
                                    "qty_item_1": $('#md_mer_qty_item').val()
                                };
                                $.get('/htmlWeb/addTrolley', _data, function (retz) {
                                });
                            } else {
                                navPills('loginHtml');
                            }
                        },
                        error: function (e) {
                            console.log('error')
                        }
                    });
                } else {
                    alert('该日期预订已满，请重新选择日期！');
                }
            }
        });
    }).on('click', '#md_direct_buy', function(e) { // 立即购买按钮点击事件
        e.stopPropagation();
        var _proId = $('#mer_detail_production span.cur input').val();
        var _schDate = $('#md_mer_date').val();
        var _dinType = $('#md_mer_date').nextAll('.cur').text();
        var _qtyItem = $('#md_mer_qty_item').val();
        if (!_proId) {
            alert('请选择商家产品！');
            return;
        } else if (!_schDate) {
            alert('请选择预约时间！');
            return;
        } else if (!_dinType) {
            alert('请选择“午餐”或是“晚宴”！');
            return;
        } else if (!_qtyItem) {
            alert('请选择数量！');
            return;
        }
        $.ajax({
            type: 'get',
            url: '/htmlWeb/isHaveOrder.json',
            async:false,
            data: {
                "userId": $('#md_mer_detail_id').val(),
                "scheduleDate": $('#md_mer_date').val(),
                "scheduleType": (_dinType == '午餐' ? 1 : 2)
            },
            dataType: 'json',
            success: function(rnData) {
                if (rnData && rnData.result == '1') {
                    $.ajax({
                        type: 'get',
                        url: '/loginWeb/isLogin.json',
                        dataType: 'json',
                        async:false,
                        data: {},
                        success: function (ret) {
                            if (ret.isLogin == 'OK') {
                                var _1 = $('#md_mer_date').nextAll('.cur').text();
                                var _data = {
                                    "biz_user_id": $('#md_mer_detail_id').val(),  // 商家ID
                                    "product_id": $('#mer_detail_production span.cur input').val(),
                                    "schedule_date": $('#md_mer_date').val(),
                                    "dinner_type": _1 == '午餐' ? '午宴' : _1,
                                    "qty_item_1": $('#md_mer_qty_item').val()
                                };
                                var dinnerType = _1 == '午餐' ? '午宴' : _1;
                                var param = "?biz_user_id=" + $('#md_mer_detail_id').val() + "&product_id=" + $('#mer_detail_production span.cur input').val() + "&schedule_date=" + $('#md_mer_date').val() +
                                    "&dinner_type=" + dinnerType;
                                window.open("htmlWeb/addDirectBuy" + param);
                                setTimeout(function(){
                                    window.location.href = "/systemMainHtml?flag='order'";
                                },500);
                            } else {
                                navPills('loginHtml');
                            }
                        },
                        error: function(e) {
                            console.log('error')
                        }
                    });
                } else {
                    alert('该日期预订已满，请重新选择日期！');
                }
            },
            error: function(e) {
                console.log(e);
            }
        });
    }).on('click', '#md_mer_problem', function(e) { // 点击“有问题，问问我吧”按钮，弹出div
        $.ajax({
            type: 'get',
            url: '/loginWeb/isLogin.json',
            dataType: 'json',
            asycn : false,
            data: {},
            success: function (ret) {
                if (ret.isLogin == 'OK') {


                } else {
                    navPills('loginHtml');
                }
            },
            error: function(e) {
                console.log('error')
            }
        });
        e.stopPropagation();
        $('.desk').fadeIn(100);
        $('.layerDiv').slideDown(200);
        $('#md_mer_mobile').val('请输入手机号');
        $('#md_mer_valid_code').val('请输入验证码');
        $('#comments').attr('placeholder', '留言内容：\n1、我的姓名：\n2、问题描述：');
        $('#comments').val('');
    }).on('click', '#md_mer_popup_div .closeDiv', function(e) { // 点击“留言弹出层”右上角“X”
        e.stopPropagation();
        $('.desk').fadeOut(100);
        $('.layerDiv').slideUp(200);
    }).on('click', '#md_mer_get_code', function (e) { // 点击“获取手机验证码”得按钮得效果
        e.stopPropagation();
        var _mobile = $('#md_mer_mobile').val();
        if(!(/^1[34578]\d{9}$/.test(_mobile))){
            alert("请填写正确的手机号码！");
        } else {
            sendValidCode();
        }
    }).on('click', '#md_mer_vcode_submit', function(e) {
        e.stopPropagation();
        var _mobile = $('#md_mer_mobile').val();
        var _vcode = $('#md_mer_valid_code').val();
        if (_mobile && _mobile != '请输入手机号' && _mobile != '') {
            if(!(/^1[34578]\d{9}$/.test(_mobile))){
                alert("请填写正确的手机号码！");
                return;
            } else if (_vcode && _vcode != '请输入验证码' && _vcode != '') {
                $.post('/htmlWeb/valid_code.json', {
                    "mobile": _mobile,
                    "vcode": _vcode,
                    "descn": $('#comments').val()
                }, function (wret) {
                    if (wret && wret.retMsg == '成功') {
                        alert('您的反馈我们已收到并及时处理，稍后与您联系，谢谢！')
                        $('#md_mer_popup_div, .desk').hide();
                    } else if (wret && wret.retMsg.indexOf('验证码错误') != -1) {
                        alert('验证码错误！');
                    }
                    clearInterval(_ai);
                    $('#md_mer_get_code').css({'background-color': '#2caeea', 'cursor': 'pointer'}).val('免费获取验证码');
                    $('html, body').on('click', '#md_mer_get_code', function (e) {
                        e.stopPropagation();
                        sendValidCode();
                    })
                });
            } else {
                alert('请输入验证码！');
            }
        } else {
            alert('请输入手机号码！');
        }
    }).on('click', '#case_list li:eq(0) em a', function(e) { // 案例类型
        e.stopPropagation();
        $('#case_list li:eq(0) em a').removeClass('cur');
        $(this).addClass('cur');
        _caseConditions.case_type = $(this).text();
        byIndexCaseData();
    }).on('click', '#case_list li:eq(1) em a', function (e) {
        e.stopPropagation();
        $('#case_list li:eq(1) em a').removeClass('cur');
        $(this).addClass('cur');
        _caseConditions.case_detail = $(this).text();
        byIndexCaseData();
    }).on('click', '#case_list li:eq(2) em a', function(e) { // 案例类型
        e.stopPropagation();
        $('#case_list li:eq(2) em a').removeClass('cur');
        $(this).addClass('cur');
        _caseConditions.case_environment = $(this).text();
        byIndexCaseData();
    }).on('click', '#case_list li:eq(3) label a', function(e) { // 案例类型
        e.stopPropagation();
        var _clz = $(this).attr('class');
        var $vle = $(this).text();
        var _orderType = '';
        if (_clz && _clz.indexOf('cur') != -1) {
            if ($vle != '综合') {
                var isAsc = $(this).hasClass('order_asc');
                if (isAsc) {
                    $(this).removeClass('order_asc').addClass('order_desc');
                    _orderType = 'desc ';
                } else {
                    $(this).removeClass('order_desc').addClass('order_asc');
                    _orderType = '';
                }
            } else {
                return;
            }
        } else {
            $('#case_list li:eq(3) label a').removeClass('cur order_asc order_desc');
            $(this).addClass('cur');
            if ($vle == '综合') {
                _orderStyle = '';
            } else if ($vle == '价格') {
                _orderStyle = ' case_detail ';
                $(this).addClass('order_asc');
            } else if ($vle == '浏览量') {
                _orderType = 'desc ';
                _orderStyle = ' goodD ';
                $(this).addClass('order_desc');
            } else if ($vle == '好评率') {
                _orderType = 'desc ';
                _orderStyle = ' goodD ';
                $(this).addClass('order_desc');
            }
        }
        _caseConditions.orderDesn = $(this).text() + '-' + _orderType;
        byIndexCaseData();
    });
});
var _ai;
function sendValidCode() {
    $('html, body').off('click', '#md_mer_get_code');
    $('#md_mer_get_code').css({'background-color': '#ccc', 'cursor': 'default'}).val('60s后可再次发送...');
    var _ai1 = 60;
    _ai = setInterval(function () {
        _ai1 = _ai1 - 1;
        if (_ai1 == 0) {
            clearInterval(_ai);
            $('#md_mer_get_code').css({'background-color': '#2caeea', 'cursor': 'pointer'}).val('免费获取验证码');
            $('html, body').on('click', '#md_mer_get_code', function (e) {
                e.stopPropagation();
                sendValidCode();
            })
        } else {
            $('#md_mer_get_code').val(_ai1 + 's后可再次发送...');
        }
    }, 1000);
    var _mobile = $('#md_mer_mobile').val();
    if (_mobile && _mobile != '请输入手机号' && _mobile != '') {
        $.post('/registerWeb/sendValidMsgWeb.json', {"mobile": _mobile}, function (ret) {
        });
    } else {
        alert('请输入手机号码！');
    }
}

_caseConditions = {};

function searchComments(page) {
    var _pageSize = 5;
    $.ajax({
        type: "get",
        url: "by/comments",
        data: {
            "page": page,
            "pageSize": _pageSize,
            "user_id": $('#md_user_id_hide').val()
        },
        dataType: "json",
        success: function(ret) {
            $('#reviews .ratiUl').empty();
            var _commentList = ret.commentList;
            var _commentTotal = ret.commentTotal;
            var _page = ret.page;
            _commentList.forEach(function (com, i) {
                var $li = $('<li></li>');
                var $li_a = $('<a href="javascript:;"></a>');
                var $li_a_img = $('<img width="56" height="56" src="http://img.boyitongcheng.com/' + (com.bizCover && com.bizCover != '' ? com.bizCover : '') + '!56x56"' +
                    ' onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                var $li_a_span = $('<span>' + (com.customName && com.customName != '' ? com.customName : '无') + '</span>');
                var $li_div = $('<div class="raTxt"></div>');
                var $li_div_h2em = $('<h2><em>评分星级：</em><div class="halfShow-true-demo" id="mer_detail_star_' + i + '"></div></h2>');
                var $li_div_p = $('<p>' + (com.customCommont ? com.customCommont : '') + '</p>');
                var $li_div_h3 = $('<h3>' + (com.evaluationTime ? formatDate(new Date(com.evaluationTime.iMillis), 'yyyy-MM-dd') : '') + '</h3>');
                $li_a.append($li_a_img).append($li_a_span);
                $li_div.append($li_div_h2em).append($li_div_p).append($li_div_h3);
                $li.append($li_a).append($li_div);
                $('#reviews .ratiUl').append($li);
                $('#mer_detail_star_' + i).raty({readOnly: true, score: com.customStar });
            });
            PageUtils(_page, _pageSize, _commentTotal);
        },
        error: function(e) {
            console.log('error');
        }
    });
}

function byIndexCasePage() {
    $('.mainDiv').load('by/adHtml', {}, function(){
        var wedTypeLink = '<a class="cur">不限</a>',wedEnvironmentLink = '<a class="cur">不限</a>';
        var wedType = getDictByType(1);
        var wedEnvironment = getDictByType(2);
        $(wedType).each(function(i,data){
            wedTypeLink += '<a>' + data.name +'</a>'
        });
        $(wedEnvironment).each(function(i,data){
            wedEnvironmentLink += '<a>' + data.name +'</a>'
        });
        $('#case_list li:eq(0) em').html(wedTypeLink);
        $('#case_list li:eq(2) em').html(wedEnvironmentLink);
        byIndexCaseData();
    });
}

function byIndexCaseData(curpage) {
    if(!curpage){
        curpage = 1;
    }
    var _data = {
        "parent_id": 6,
        "position_id": 3,
        "flag" : "case",
        "page" : curpage
    };
    _data = $.extend({}, _caseConditions, _data);
    $.ajax({
        type: "get",
        url: "by/adList",
        data: _data,
        dataType: "json",
        success: function(ret) {
            $('#com_list_ul').empty();
            if (ret && ret.total && ret.total > 0) {
                var bizList = ret.bizList;
                if (bizList && bizList.length > 0) {
                    bizList.forEach(function (biz, i) {
                        var $li = $('<li ' + (i % 4 == 3 ? 'style="margin-right: 0px; float: right;"' : '') + '></li>');
                        var $li_div = $('<div class="caseM"></div>');
                        var img = biz.imgUrl ? biz.imgUrl : '';
                        var $li_div_img = $('<img style="cursor: pointer" src="http://img.boyitongcheng.com/' + img + '" ' +
                            'onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                        var $li_div_a = "";
                        if(biz.exampleType == 2){
                            $li_div_a = $('<a target="_blank" href="' + biz.descn + '">' + (biz.name && biz.name != '' ? biz.name : '未知') + '</a>');
                        }else{
                            $li_div_a = $('<a href="javascript:;">' + (biz.name && biz.name != '' ? biz.name : '未知') + '</a>');
                        }
                        var $li_div_h5 = $('<h5>￥' + (biz.caseDetail && biz.caseDetail != '' && !isNaN(biz.caseDetail) ? biz.caseDetail : '0') + '</h5>');
                        var $li_div_h6 = $('<h6><em class="ico">评论：' + (biz.totalD && biz.totalD != '' ? biz.totalD : '0') + '</em>' +
                            '<em class="ico1">好评：' + (biz.goodD && biz.goodD != '' ? (biz.goodD / biz.totalD * 100) + '%' : '0%') + '</em>' +
                            '<em class="ico2">浏览：' + (biz.viewCount && biz.viewCount != '' ? biz.viewCount : '0') + '</em></h6>');
                        var $li_div_hide = $('<input type="hidden" value="' + biz.id + '@' + biz.exampleType + '" />');
                        $li_div.append($li_div_img).append($li_div_a).append($li_div_h5).append($li_div_h6).append($li_div_hide);
                        $li.append($li_div);
                        $('#com_list_ul').append($li);
                    });
                } else {
                    $('#com_list_ul').append('<li style="width: 100%; font-size: 20px; text-align: center;">暂无数据！</li>');
                }
                if (ret.total > ret.pageSize) {
                    PageUtilsCase(ret.currentPage, ret.pageSize, ret.total);
                }
            } else {
                $('#com_list_ul').append('<li style="width: 100%; font-size: 20px; text-align: center;">暂无数据！</li>');
            }
        },
        error: function (e) {
            console.log('error');
        }
    });
}

// 判断翻页时的页数
function judgePage(page) {
    // 若为"prev"与"next"，则表示为上一页或下一页
    var $curPage = $('#curPage').val();
    if (page == '上一页') {
        page = parseInt($curPage) - 1;
    } else if (page == '下一页') {
        page = parseInt($curPage) + 1;
    }
    return page;
}
// 首页搜索框数据加载
function byIndexSearchPage(e) {
    e = e || window.event;
    if ($(e.target).attr('id') === 'by_index_search_btn') {
        _conditions = {"page": 1, "keyword": $('#by_index_search_ipt').val(), "isSearch": true};
    }
    listDivHidden();
    $('.mainDiv').load('by/compereHtml', {}, byIndexSearchData(_conditions));
}

function byIndexSearchData(opts) {
    var keyId = $("#keyId").val();
    if(keyId && keyId != ""){
        opts = $.extend({}, opts, {"key_id" : keyId});
    }
    var _defaults = {
        "parent_id": -1,
        "channel_id": 0,
        "position_id": 0,
        "style_type": 0,
        "price": 0,
        "area": 0,
        // "city": opts.isSearch ? $('.div_Adress span').text() : '', // 所选城市
        "city": $('.div_Adress span').text(),
        "page": 1,
        "_": new Date().getTime()
    }
    var _data = $.extend({}, _defaults, opts);
    $.ajax({
        url: "by/merchants",
        data: _data,
        error: function(e) {
        },
        success: function(ret) {
            debugger
            $('#com_list_ul').empty();
            if (ret && ret.total && ret.total > 0) {
                var bizList = ret.bizList;
                if (bizList && bizList.length > 0) {
                    for (var i = 0, len = bizList.length; i < len; i++) {
                        var biz = bizList[i];
                        var $li = $('<li ' + (i % 4 == 3 ? 'style="margin-right: 0px; float: right;"' : '') + '></li>');
                        var $li_div = $('<div class="caseM"></div>');
                        var img = (biz.bizCover && biz.bizCover != '' ? (biz.bizCover + '!500x500') : (biz.avatar + '!500x500'));
                        var $li_div_img = $('<img style="cursor: pointer" src="http://img.boyitongcheng.com/' + img + '" ' +
                            'onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                        var $li_div_a = $('<a href="javascript:;">' + (biz.cnName && biz.cnName != '' ? biz.cnName : '未知') + '</a>');
                        var $li_div_h5 = $('<h5>￥' + (biz.bizPrice && biz.bizPrice != '' ? biz.bizPrice : '0') + '</h5>');
                        var $li_div_h5_span = '<span>${1}${2}${3}</span>';
                        var ut_1 = '', ut_2 = '', ut_3 = '';
                        var _authList = biz.authList;
                        _authList.forEach(function (auth) {
                            if (auth.authType == 1) {
                                ut_1 = '<img class="zzImg" src="/common/icon/platform.gif" width="40px" height="40px" title="平台认证"/>';
                            } else if (auth.authType == 2) {
                                ut_2 = '<img class="zzImg" src="/common/icon/credit.gif" width="40px" height="40px" title="诚信认证"/>';
                            } else {
                                if (auth.authLevel == 1) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/primary.gif" width="40px" height="40px" title="个人-初级认证"/>';
                                } else if (auth.authLevel == 2) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/middle.gif" width="40px" height="40px" title="个人-中级认证"/>';
                                } else if (auth.authLevel == 3) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/senior.gif" width="40px" height="40px" title="个人-高级认证"/>';
                                } else if (auth.authLevel == 4) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/master.gif" width="40px" height="40px" title="个人-大师认证"/>';
                                } else if (auth.authLevel == 5) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/director.gif" width="40px" height="40px" title="个人-总监认证"/>';
                                } else if (auth.authLevel == 6) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/crown.gif" width="40px" height="40px" title="个人-皇冠认证"/>';
                                } else if (auth.authLevel == 7) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/king.gif" width="40px" height="40px" title="个人-金冠认证"/>';
                                } else if (auth.authLevel == 8) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/one_star.gif" width="40px" height="40px" title="团队-一星白银团队"/>';
                                } else if (auth.authLevel == 9) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/two_star.gif" width="40px" height="40px" title="团队-二星黄金团队"/>';
                                } else if (auth.authLevel == 10) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/three_star.gif" width="40px" height="40px" title="团队-三星白金团队"/>';
                                } else if (auth.authLevel == 11) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/four_star.gif" width="40px" height="40px" title="团队-四星钻石团队"/>';
                                } else if (auth.authLevel == 12) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/five_star.gif" width="40px" height="40px" title="团队-五星大师团队"/>';
                                } else if (auth.authLevel == 13) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/six_star.gif" width="40px" height="40px" title="团队-六星皇冠团队"/>';
                                } else if (auth.authLevel == 14) {
                                    ut_3 = '<img class="zzImg" src="/common/icon/seven_star.gif" width="40px" height="40px" title="团队-七星至尊团队"/>';
                                }
                            }
                        });
                        $li_div_h5_span = $li_div_h5_span.replace('${1}', ut_1).replace('${2}', ut_2).replace('${3}', ut_3);
                        $li_div_h5.prepend($li_div_h5_span);
                        var $li_div_h6 = $('<h6><em class="ico">评论：' + (biz.bizCommentCount && biz.bizCommentCount != '' ? biz.bizCommentCount : '0') + '</em>' +
                            '<em class="ico1">好评：' + (biz.bizStar && biz.bizStar != '' ? biz.bizStar : '0') + '</em>' +
                            '<em class="ico2">浏览：' + (biz.bizViewCount && biz.bizViewCount != '' ? biz.bizViewCount : '0%') + '</em></h6>');
                        var $li_div_hide = $('<input type="hidden" value="' + biz.id + '"/>');
                        $li_div.append($li_div_img).append($li_div_a).append($li_div_h5).append($li_div_h6).append($li_div_hide);
                        $li.append($li_div);
                        $('#com_list_ul').append($li);
                    }
                } else {
                    $('#com_list_ul').append('<li style="width: 100%; font-size: 20px; text-align: center;">暂无数据！</li>');
                }
                if (ret.total > ret.pageSize) {
                    PageUtils(ret.currentPage, ret.pageSize, ret.total);
                }
            } else {
                $('#com_list_ul').append('<li style="width: 100%; font-size: 20px; text-align: center;">暂无数据！</li>');
            }
        }
    });
}

function PageUtilsCase(page, size, total) {
    var $a_prev, a_num = "", $a_next, totalPage = 0;
    if (page == 1) {
        $a_prev = $('<span>上一页</span>');
    } else {
        $a_prev = $('<a href="javascript:;">上一页</a>');
    }
    if (total / size > parseInt(total / size)) {
        totalPage = parseInt(total / size) + 1;
    } else {
        totalPage = parseInt(total / size);
    }
    for (var i = 1; i <= totalPage; i++) {
        if (i == page) {
            a_num += '<a class="cur nowPage">' + i + '</a>';
        } else {
            a_num += '<a href="javascript:;">' + i + '</a>';
        }
    }
    if (page == totalPage) {
        $a_next = $('<span>下一页</span>');
    } else {
        $a_next = $('<a href="javascript:;">下一页</a>');
    }
    var $hide = $('<input type="hidden" id="curPage" value="' + page + '"/>' +
        '<input type="hidden" id="totalPage" value="' + totalPage + '"/>');
    $('.page').empty().append($a_prev).append(a_num).append($a_next).append($hide);
    $(".page a").on("click",function(){
        var nowPage = $(this).html();
        if(isNaN(nowPage)){
            if(nowPage == '上一页'){
                nowPage = page - 1 > 1 ? page - 1 : 1;
            }else if(nowPage == '下一页'){
                nowPage = page + 1 <= totalPage ? page + 1 : totalPage;
            }
        }
        byIndexCaseData(nowPage);
    })
}
function PageUtils(page, size, total) {
    var $a_prev, a_num = "", $a_next, totalPage = 0;
    if (page == 1) {
        $a_prev = $('<span>上一页</span>');
    } else {
        $a_prev = $('<a href="javascript:;">上一页</a>');
    }
    if (total / size > parseInt(total / size)) {
        totalPage = parseInt(total / size) + 1;
    } else {
        totalPage = parseInt(total / size);
    }
    for (var i = 1; i <= totalPage; i++) {
        if (i == page) {
            a_num += '<span>' + i + '</span>';
        } else {
            a_num += '<a href="javascript:;">' + i + '</a>';
        }
    }
    if (page == totalPage) {
        $a_next = $('<span>下一页</span>');
    } else {
        $a_next = $('<a href="javascript:;">下一页</a>');
    }
    var $hide = $('<input type="hidden" id="curPage" value="' + page + '"/>' +
        '<input type="hidden" id="totalPage" value="' + totalPage + '"/>');
    $('.page').empty().append($a_prev).append(a_num).append($a_next).append($hide);
}

// 加载商家详情页面(仅加载页面，数据单独加载)
function loadDetailPage(userId) {
    listDivHidden();
    if(String(userId).indexOf("@") != -1){
        if(userId.split("@").length > 1 && userId.split("@")[1] == 3){
            $('.mainDiv').load('case_DetailsHtml', {}, function(){
                $("#caseIdHidden").val(userId.split("@")[0]);
                setTimeout(function(){
                    $.getScript("../../by-webhtml/assets/js/case_Details.js");
                },100);

            });
        }
    }else{
        $('.mainDiv').load('by/detailHtml', {}, loadDetailData(userId));
    }
}

// 加载商家详情数据
function loadDetailData(userId) {
    var city = $("#mainCity span").html();
    if(city == '全国'){
        city = null;
    }
    $.ajax({
        type: "get",
        url: "by/detailData",
        data: {
            "user_id": userId,
            "city" : city
        },
        error: function (e) {
            console.log(e);
        },
        success: function (ret) {
            if (ret) {
                $('#md_mer_date').val('');
                var _user = ret.user, _channel = ret.channel, _authList = ret.authList, _productList = ret.productList
                _openCities = ret.openCitiesMap, _recommend = ret.recommendUsers, _exampleList = ret.exampleList
                _comments = ret.comments, _youLikeListB = ret.youLikeListB;
                if (_user) {
                    $('#mer_detail_uType').text(_channel.name);
                    $('#mer_detail_name').text(_user.cnName).append('<input type="hidden" id="md_mer_detail_id" value="' +
                        _user.id + '"/>');
                    $('#mer_detail_img').attr('src', _user.bizCover ? 'http://img.boyitongcheng.com/' + _user.bizCover + '!500x500' : '')
                        .attr('onerror', 'javascript: this.src="/by-webhtml/assets/image/noImg.png"');
                    $('#mer_detail_ge').html('<em>预定量：' + (_user.bizDealCount && _user.bizDealCount != '' ? _user.bizDealCount : '0') + '</em>' +
                        '<em>评论数：' + (_user.bizCommentCount && _user.bizCommentCount != '' ? _user.bizCommentCount : '0') + '</em>' +
                        '<em>好评率：' + (_user.bizStar && _user.bizStar != '' ? _user.bizStar : '0%') + '</em>' +
                        '<em>浏览量：' + (_user.bizViewCount && _user.bizViewCount != '' ? _user.bizViewCount : '0') + '</em>');
                    $('#mer_detail_nameType').html('<span>' + _user.cnName + '</span>' +
                        '<em>' + _channel.name + '</em>' +
                        '<b>' + (_user.userType && _user.userType == 3 ? '个人' : (
                                _user.userType && _user.userType == 4 ? '团队' : _user.userType && _user.userType == 5 ? '区域加盟商' : ''
                            )) + '</b>').append('<input type="hidden" id="md_user_id_hide" value="' + _user.id + '"/>'); // 此处需要修改，数据库暂无字段
                    $('#mer_detail_local').html('<span>所在地：' + (_user['city'] && _user['city'] != '' ? _user['city'] : '未知') + '</span>' +
                        '<em class="detaEm"><b>分享到：</b><a class="ico" href="#"></a><a class="ico1" href="#"></a></em>');
                    var _creditData = _user.bizDealCount ? _user.bizDealCount : 0;
                    var _creditStr = '';
                    if (_creditData && _creditData != 0) {
                        var _1 = Math.floor(_creditData / 1250); // 判断是否有至尊图标
                        if (_1 >= 1) {
                            for (var i = 0; i < _1; i++) {
                                _creditStr += '<img src="/common/icon/credit_5.gif" width="40px" height="40px" title="信誉值：' + _creditData + '"/>';
                            }
                        }
                        var _2 = Math.floor((_creditData - (1250 * _1)) / 250); // 判断是否有皇冠图标
                        if (_2 >= 1) {
                            for (var i = 0; i < _2; i++) {
                                _creditStr += '<img src="/common/icon/credit_4.gif" width="40px" height="40px" title="信誉值：' + _creditData + '"/>';
                            }
                        }
                        var _3 = Math.floor((_creditData - (1250 * _1) - (250 * _2)) / 50); // 判断是否有钻石图标
                        if (_3 >= 1) {
                            for (var i = 0; i < _3; i++) {
                                _creditStr += '<img src="/common/icon/credit_3.gif" width="40px" height="40px" title="信誉值：' + _creditData + '"/>';
                            }
                        }
                        var _4 = Math.ceil((_creditData - (1250 * _1) - (250 * _2) - (50 * _3)) / 10); // 判断是否有星星图标
                        if (_4 >= 1) {
                            for (var i = 0; i < _4; i++) {
                                _creditStr += '<img src="/common/icon/credit_2.gif" width="40px" height="40px" title="信誉值：' + _creditData + '"/>';
                            }
                        }
                    }
                    $('#mer_detail_credi').html('<span>信誉：' + _creditStr + '</span>');
                    var authStr = '<span>资质：${1}${2}${3}</span>';
                    var ut_1 = '', ut_2 = '', ut_3 = '';
                    _authList.forEach(function (auth) {
                        if (auth.authType == 1) {
                            ut_1 = '<img src="/common/icon/platform.gif" width="40px" height="40px" title="平台认证"/>';
                        } else if (auth.authType == 2) {
                            ut_2 = '<img src="/common/icon/credit.gif" width="40px" height="40px" title="诚信认证"/>';
                        } else {
                            if (auth.authLevel == 1) {
                                ut_3 = '<img src="/common/icon/primary.gif" width="40px" height="40px" title="个人-初级认证"/>';
                            } else if (auth.authLevel == 2) {
                                ut_3 = '<img src="/common/icon/middle.gif" width="40px" height="40px" title="个人-中级认证"/>';
                            } else if (auth.authLevel == 3) {
                                ut_3 = '<img src="/common/icon/senior.gif" width="40px" height="40px" title="个人-高级认证"/>';
                            } else if (auth.authLevel == 4) {
                                ut_3 = '<img src="/common/icon/master.gif" width="40px" height="40px" title="个人-大师认证"/>';
                            } else if (auth.authLevel == 5) {
                                ut_3 = '<img src="/common/icon/director.gif" width="40px" height="40px" title="个人-总监认证"/>';
                            } else if (auth.authLevel == 6) {
                                ut_3 = '<img src="/common/icon/crown.gif" width="40px" height="40px" title="个人-皇冠认证"/>';
                            } else if (auth.authLevel == 7) {
                                ut_3 = '<img src="/common/icon/king.gif" width="40px" height="40px" title="个人-金冠认证"/>';
                            } else if (auth.authLevel == 8) {
                                ut_3 = '<img src="/common/icon/one_star.gif" width="40px" height="40px" title="团队-一星白银团队"/>';
                            } else if (auth.authLevel == 9) {
                                ut_3 = '<img src="/common/icon/two_star.gif" width="40px" height="40px" title="团队-二星黄金团队"/>';
                            } else if (auth.authLevel == 10) {
                                ut_3 = '<img src="/common/icon/three_star.gif" width="40px" height="40px" title="团队-三星白金团队"/>';
                            } else if (auth.authLevel == 11) {
                                ut_3 = '<img src="/common/icon/four_star.gif" width="40px" height="40px" title="团队-四星钻石团队"/>';
                            } else if (auth.authLevel == 12) {
                                ut_3 = '<img src="/common/icon/five_star.gif" width="40px" height="40px" title="团队-五星大师团队"/>';
                            } else if (auth.authLevel == 13) {
                                ut_3 = '<img src="/common/icon/six_star.gif" width="40px" height="40px" title="团队-六星皇冠团队"/>';
                            } else if (auth.authLevel == 14) {
                                ut_3 = '<img src="/common/icon/seven_star.gif" width="40px" height="40px" title="团队-七星至尊团队"/>';
                            }
                        }
                    });
                    authStr = authStr.replace('${1}', ut_1).replace('${2}', ut_2).replace('${3}', ut_3);
                    $('#mer_detail_qual').html(authStr);
                    $('#mer_detail_enterTime').html('<span>入驻时间：' + (_user.createTime && _user.createTime.iMillis ?
                            formatDate(new Date(_user.createTime.iMillis), 'yyyy-MM-dd') : '未知') + '</span>');
                    _productList.forEach(function (pro, i) {
                        var $production = $('<span><em class="ico">' + pro.name + '</em><em class="ico1">￥ ' + pro.currentPrice + '</em></span>');
                        $('#mer_detail_production').append($production);
                        $('#mer_detail_production span').append('<input type="hidden" id="md_mer_prod_id' + i + '" value="' + pro.id + '"/>');
                    });
                    // 商家简介
                    $('#business .ud_business_intro').html(_user['descn'] ? _user['descn'] : '暂无商家简介');
                    // 服务内容
                    $('#service div').nextAll('p').remove();
                    $('#service div:eq(0)').after(_user.tagNames && _user.tagNames != 'null' && _user.tagNames != '' ? _user.tagNames : '暂无服务内容');
                    // var cities = _openCities['四川省'];
                    // 开通城市
                    if (_openCities) {
                        for (var key in _openCities) {
                            var cities = _openCities[key];
                            cities.forEach(function (city) {
                                var $a = $('<a>' + city + '</a>');
                                $('#area .areaDiv').append($a);
                            });
                        }
                    } else {
                        $('#area .areaDiv').html('暂无开通城市');
                    }
                    // 推荐团队
                    _recommend.forEach(function (rec, i) {
                        var $li = $('<li ' + (i % 3 == 2 ? 'style="margin-right: 0px; float: right;"' : '') + '></li>');
                        var $li_div = $('<div class="teamLi"></div>');
                        var $li_div_img = $('<img src="http://img.boyitongcheng.com/' + (rec.recommendUser.avatar ? rec.recommendUser.avatar : '') + '" ' +
                            'onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                        var $li_div_div = $('<div class="teamTxt"></div>');
                        var value = ((rec.recommendUser.bizWork && rec.recommendUser.bizWork.name ? (rec.recommendUser.bizWork.name + '：') : '') + (rec.recommendUser.cnName ? rec.recommendUser.cnName : ''));
                        var $li_div_div_a = $('<a href="javascript:;" title="' + value + '">' + (value && value.length > 17 ?
                                value.substr(0, 17) + '...' : value) + '</a>');
                        var $li_div_div_hide = $('<input type="hidden" value="' + rec.recommendUser.id + '"/>');
                        var $li_div_div_h5 = $('<h5>￥' + (rec.recommendUser.bizPrice ? rec.recommendUser.bizPrice : '0') + '</h5>');
                        var $li_div_div_h6 = $('<h6>100%好评率<em>|</em>' + (rec.recommendUser.bizDealCount &&
                            rec.recommendUser.bizDealCount != '' ? rec.recommendUser.bizDealCount : '0') + '预定量</h6>');
                        $li_div_div.append($li_div_div_a).append($li_div_div_hide).append($li_div_div_h5).append($li_div_div_h6);
                        $li_div.append($li_div_img).append($li_div_div);
                        $li.append($li_div);
                        $('#commend .teamDiv').append($li);
                    });
                    // 作品列表
                    _exampleList.forEach(function (exa, i) {
                        var $li = $('<li ' + (i % 4 == 3 ? 'style="margin-bottom: 0px; margin-right: 0px; float: right;"' : '') + '></li>');
                        var $li_div = $('<div class="caseM"></div>');
                        var $li_div_img = $('<img style="cursor: pointer;" onclick="showCaseDetailIndex(' + exa.id + ')" src="http://img.boyitongcheng.com/' + (exa.imgUrl ? exa.imgUrl : '') + '"' +
                            'onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                        var $li_div_a = $('<a href="javascript:;" onclick="showCaseDetailIndex(' + exa.id + ')">' + exa.name + '</a>');
                        if(exa.exampleType == 2){
                            $li_div_img = $('<img style="cursor: pointer;" onclick="javascript:window.open(\'' + exa.descn + '\')" src="http://img.boyitongcheng.com/' + (exa.imgUrl ? exa.imgUrl : '') + '"' +
                                'onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/></a>');
                            $li_div_a = $('<a href="' + exa.descn +'" target="_blank">' + exa.name + '</a>');
                        }
                        $li_div.append($li_div_img).append($li_div_a);
                        $li.append($li_div);
                        $('#works .caseList').append($li);
                    });
                    // 评论列表
                    if (_comments && _comments.length != 0) {
                        var _commentList = _comments.commentList;
                        var _commentTotal = _comments.commentTotal;
                        if (_commentTotal != 0) {
                            _commentList.forEach(function (com, i) {
                                var $li = $('<li></li>');
                                var $li_a = $('<a href="javascript:;"></a>');
                                console.log(com.bizCover)
                                var $li_a_img = $('<img width="56" height="56" src="http://img.boyitongcheng.com/' + (com.bizCover && com.bizCover != '' ? com.bizCover : '') + '"' +
                                    ' onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                                var $li_a_span = $('<span>' + (com.customName && com.customName != '' ? com.customName : '无') + '</span>');
                                var $li_div = $('<div class="raTxt"></div>');
                                var $li_div_h2em = $('<h2><em>评分星级：</em><div class="halfShow-true-demo" id="mer_detail_star_' + i + '"></div></h2>');
                                var $li_div_p = $('<p>' + (com.customCommont ? com.customCommont : '') + '</p>');
                                var $li_div_h3 = $('<h3>' + (com.evaluationTime ? formatDate(new Date(com.evaluationTime.iMillis), 'yyyy-MM-dd') : '') + '</h3>');
                                $li_a.append($li_a_img).append($li_a_span);
                                $li_div.append($li_div_h2em).append($li_div_p).append($li_div_h3);
                                $li.append($li_a).append($li_div);
                                $('#reviews .ratiUl').append($li);
                                $('#mer_detail_star_' + i).raty({readOnly: true, score: com.customStar });
                            });
                            PageUtils(1, 5, _commentTotal);
                        } else {
                            $('#reviews .ratiUl').append('<li class="noData">暂无评价！</li>');
                        }
                    }
                    _youLikeListB.forEach(function (yl, i) {
                        // <li><span><img src="temp/img10.jpg" /><a href="#">经典全套三亚蜜月之旅</a><h2>¥ 36588</h2><h3><em class="ico">3467</em><em class="ico1">242</em></h3></span></li>
                        var $li = $('<li></li>');
                        if(i % 5 == 0 && _youLikeListB.length > 4){
                            $li = $('<li style="margin-right: 0px; float: right;"></li>');
                        }
                        var $li_span = $('<span></span>');
                        var $li_span_img = $('<img width="220" onclick="showCaseDetailIndex(' + yl.id + ')" style="cursor:pointer;" height="182" src="http://img.boyitongcheng.com/' + (yl.imgUrl ? yl.imgUrl : '') +
                            '" onerror="javascript: this.src=\'/by-webhtml/assets/image/noImg.png\'"/>');
                        var $li_span_a = $('<a href="javascript:;" onclick="showCaseDetailIndex(' + yl.id + ')">' + (yl.name ? yl.name : '') + '</a>');
                        var $li_span_h2 = $('<h2>￥' + (yl.caseDetail && yl.caseDetail != '' && !isNaN(yl.caseDetail) ? yl.caseDetail : '0') + '</h2>');
                        var $li_span_h3 = $('<h3></h3>');
                        var $li_span_h3_em1 = $('<em class="ico">' + (yl.viewCount ? yl.viewCount : '0') + '</em>');
                        var $li_span_h3_em2 = $('<em class="ico1">' + (yl.totalD ? yl.totalD : '0') + '</em>');
                        $li_span_h3.append($li_span_h3_em1).append($li_span_h3_em2);
                        $li_span.append($li_span_img).append($li_span_a).append($li_span_h2).append($li_span_h3);
                        $li.append($li_span);
                        $('.partic ul').append($li);
                    });
                }

                // 获取当前年月
                var _curDate1 = new Date();
                var _curDate = formatDate(_curDate1, 'yyyy年MM月');
                var _date_hide = formatDate(_curDate1, 'yyyy-MM');
                $('#schedule label b').text(_curDate).after('<input type="hidden" id="md_cur_date" value="' + _date_hide + '"/>');
                // 获取档期
                renderSchedule(new Date(_curDate1.getFullYear(), _curDate1.getMonth(), '01'), ret.scheduleData);

                bindDateEvent(userId);
            }
        }
    });
}

function showCaseDetailIndex(id) {
    var city = $("#mainCity span").html();
    window.open("/?flag=caseDetail&city=" + city + "&caseId="+id);
}

/**
 * 绑定商家档期翻日历事件
 */
function bindDateEvent(userId) {
    /**
     * 上一月
     */
    $('html, body').on('click', '#schedule label a:eq(0)', function (e) {
        e.stopPropagation();
        $.ajax({
            type: "get",
            url: "by/schedule",
            data: {
                "user_id": userId
            },
            error: function (e) {
                console.log(e);
            },
            success: function (ret) {
                var $curDate = $('#md_cur_date').val();
                var preDate = getPreMonth($curDate);
                var md_show_date = formatDate(preDate, 'yyyy年MM月');
                var md_hide_date = formatDate(preDate, 'yyyy-MM');
                $('#schedule label b').text(md_show_date);
                $('#md_cur_date').val(md_hide_date);
                renderSchedule(preDate, ret.scheduleData);
            }
        });
    });

    /**
     * 下一月
     */
    $('html, body').on('click', '#schedule label a:eq(1)', function (e) {
        e.stopPropagation();
        $.ajax({
            type: "get",
            url: "by/schedule",
            data: {
                "user_id": userId
            },
            error: function (e) {
                console.log(e);
            },
            success: function (ret) {
                var $curDate = $('#md_cur_date').val();
                var nextDate = getNextMonth($curDate);
                var md_show_date = formatDate(nextDate, 'yyyy年MM月');
                var md_hide_date = formatDate(nextDate, 'yyyy-MM');
                $('#schedule label b').text(md_show_date);
                $('#md_cur_date').val(md_hide_date);
                renderSchedule(nextDate, ret.scheduleData);
            }
        });
    });
}

/**
 * 渲染商家档期展示页面
 * @param date 日期
 */
function renderSchedule(date, sche) {
    var _dateObj = formatDate(date, 'yyyy-MM');
    var _year = date.getFullYear();
    // 获取当前时间月份
    var _month = date.getMonth();
    _month = _month < 10 ? '0' + _month : _month;
    // 根据月份获取当前月份天数
    var days = getDateByMonth(_dateObj);
    $('#schedule .calendar h2:eq(0) em').remove();
    $('#schedule .calendar h2:eq(1) em').remove();
    $('#schedule .calendar h2:eq(2) em').remove();
    $('#schedule .calendar h2:eq(3) em').remove();
    // 获取当前时间第一天的星期数
    var _week = parseInt(date.getDay());
    var _weeks = ["七", "一", "二", "三", "四", "五", "六"];
    for (var i = 1; i <= days; i++, _week++) {
        // 渲染日期天数
        $('#schedule .calendar h2:eq(0)').append('<em>' + i + '</em>');

        // 渲染星期数
        if (_week > 6) {
            _week = 0;
        }
        $('#schedule .calendar h2:eq(1)').append('<em>' + _weeks[_week] + '</em>');
        var _m = parseInt(_month) + 1;
        var _1 = _year + (_m < 10 ? '0' + _m : _m + '') + (i < 10 ? '0' + i : i + '');
        $('#schedule .calendar h2:eq(2)').append('<em id="lunch_' + _1 + '" class="ico1"></em>');
        $('#schedule .calendar h2:eq(3)').append('<em id="dinner_' + _1 + '" class="ico1"></em>');
    }
    if (sche && sche != '') {
        var _scheObj = eval('(' + sche + ')');
        for (var key in _scheObj) {
            var _key0 = key.split('-')[0];
            var _key1 = key.split('-')[1];
            if (_key1 == 1) {
                $('#lunch_' + _key0).removeClass('ico1').addClass('ico');
            } else if (_key1 == 2) {
                $('#dinner_' + _key0).removeClass('ico1').addClass('ico');
            }
        }
    }
}

/**
 * 文本框时间改变事件
 */
function md_date_change(datas) {
    _conditions.conv_date = datas;
    byIndexSearchData(_conditions);
}